package com.example.smart2.ui.service;

import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.SearchView;

import android.os.Bundle;
import android.widget.ImageView;


import com.bumptech.glide.Glide;
import com.example.smart2.R;
import com.example.smart2.base.BaseActivity;
import com.example.smart2.model.BannerParkModel;
import com.example.smart2.network.ApiService;
import com.youth.banner.Banner;
import com.youth.banner.adapter.BannerImageAdapter;
import com.youth.banner.holder.BannerImageHolder;
import com.youth.banner.indicator.CircleIndicator;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

public class StopCarActivity extends BaseActivity {

    private Banner banner;
    private SearchView searchView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_stop_car);
        setTitle("爱心捐赠",true);

        banner=(Banner) findViewById(R.id.banner);
        banner.addBannerLifecycleObserver(this);
        banner.setIndicator(new CircleIndicator(getApplicationContext()));

        searchView=(SearchView) findViewById(R.id.searchView);
        searchView.setQueryHint("你好！爱心人士！");//提示输入
        getBanner2();
    }

    private void getBanner2(){
        Retrofit retrofit=new Retrofit.Builder()
                .baseUrl("http://124.93.196.45:10001")
                .addConverterFactory(GsonConverterFactory.create())
                .build();
        ApiService api=retrofit.create(ApiService.class);
        api.getBanner2().enqueue(new Callback<BannerParkModel>() {
            @Override
            public void onResponse(Call<BannerParkModel> call, Response<BannerParkModel> response) {
                banner.setAdapter(new BannerImageAdapter<BannerParkModel.RowsBean>(response.body().getRows()) {
                    @Override
                    public void onBindView(BannerImageHolder bannerImageHolder, BannerParkModel.RowsBean rowsBean, int i, int i1) {
                        String str="http://124.93.196.45:10001";
                        Glide.with(getApplicationContext())
                                .load(str+rowsBean.getAdvImg())
                                .placeholder(R.drawable.slide1)
                                .into(bannerImageHolder.imageView);
                        bannerImageHolder.imageView.setScaleType(ImageView.ScaleType.FIT_XY);

                    }
                });
            }

            @Override
            public void onFailure(Call<BannerParkModel> call, Throwable throwable) {

            }
        });
    }
}